package com.darren.archive.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.darren.framework.entity.BaseEntity;
import com.darren.framework.utils.Constant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.ResultCheckStyle;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.List;

/**
 * 部门实体，数据表增删改查时使用的实体对象
 *
 * @author: darren
 * @date: 2019/12/16 10:51
 */
@ApiModel(value = "系统部门信息")
@Entity
@Table(name = Constant.TABLE_NAME_PREV + "department")
@SQLDelete(sql = "update " + Constant.TABLE_NAME_PREV + "department set is_delete = true,version=version+1 where id=? and version=?", check = ResultCheckStyle.COUNT)
@Where(clause = " is_delete  = false ")
public class SysDepartment extends BaseEntity implements Serializable {

    private static final long serialVersionUID = -2015125588403190022L;

    /**
     * 上级部门  id，引用当前表的id字段
     */
    @ApiModelProperty(notes = "上级部门  id，引用当前表的id字段")
    @Column(name = "parent_id", columnDefinition = "bigint not null default 0 comment '上级部门  id'")
    private Long parentId;

    /**
     * 部门简称
     */
    @ApiModelProperty(notes = "部门简称")
    @Column(name = "short_name", columnDefinition = "varchar(50) not null comment '部门简称'")
    private String shortName;


    /**
     * 部门名称(全称)
     */
    @ApiModelProperty(notes = "部门名称(全称)")
    @Column(name = "full_name", columnDefinition = "varchar(100) not null comment '部门名称(全称)'")
    private String fullName;


    /**
     * 部门负责人，真实姓名
     */
    @ApiModelProperty(notes = "负责人姓名")
    @Column(name = "manager_name", columnDefinition = "varchar(30) default '' comment '负责人姓名，引用用户表姓名 name'")
    private String managerName;

    /**
     * 负责人id,外键，引用用户表Id
     */
    @ApiModelProperty(notes = "负责人id,外键，引用用户表Id")
    @Column(name = "manager_id", columnDefinition = "bigint  default 0 comment '负责人id,外键，引用用户表Id'")
    private Long managerId;

    /**
     * 部门地址
     */
    @ApiModelProperty(notes = "部门地址")
    @Column(name = "address", columnDefinition = "varchar(30) default '' comment '部门地址'")
    private String address;

    /**
     * 组织机构电话
     */
    @ApiModelProperty(notes = "组织机构电话")
    @Column(name = "telephone", columnDefinition = "varchar(20) default '' comment '组织机构电话'")
    private String telephone;

    @Column(name = "icon", columnDefinition = "varchar(128) default '' comment '图标'")
    private String icon;

    /**
     * 显示顺序
     */
    @ApiModelProperty(hidden = true)
    @Column(name = "display_sequence", columnDefinition = "varchar(10) default '100000' comment '显示顺序'")
    private String displaySequence;

    @Transient
    private List<SysDepartment> children;

    @Transient
    @JSONField(serialize = false)
    private Boolean hasChildren = false;

    public Boolean getHasChildren() {
        return (children == null || children.size() == 0)?false:true;
    }

    public void setHasChildren(Boolean hasChildren) {
        this.hasChildren = hasChildren;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getShortName() {
        return shortName;
    }

    public void setShortName(String shortName) {
        this.shortName = shortName;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getManagerName() {
        return managerName;
    }

    public void setManagerName(String managerName) {
        this.managerName = managerName;
    }

    public Long getManagerId() {
        return managerId;
    }

    public void setManagerId(Long managerId) {
        this.managerId = managerId;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getDisplaySequence() {
        return displaySequence == null ? "100000":displaySequence;
    }

    public void setDisplaySequence(String displaySequence) {
        this.displaySequence = displaySequence;
    }

    public List<SysDepartment> getChildren() {
        return children;
    }

    public void setChildren(List<SysDepartment> children) {
        this.children = children;
    }
}